//
//  TLWelcomeViewController.swift
//  TLSinaWeiBo
//
//  Created by 谭亮 on 16/5/23.
//  Copyright © 2016年 tanliang. All rights reserved.
//

import UIKit
import SnapKit
class TLWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
        prepareUI()
    
    }
    
    //
    private func prepareUI() {
        // self.view添加子控件
        self.view.addSubview(bkgView)
        view.addSubview(iconView)
        view.addSubview(messageLabel)
        
        //autolayout
        // 约束背景
        // bkgView: 表示要添加约束的view
        // snp_makeConstaraints: 要添加约束
        // make: 要添加的约束的view
        bkgView.snp_makeConstraints { (make) -> Void in
            // 填充父控件
            make.edges.equalTo(self.view)
            
            // 约束头像
            iconView.snp_makeConstraints(closure: { (make) -> Void in
                // make.centerX: 要约束view的centerX属性
                // equalTo: 参照
                // self.view: 参照的view
                // snp_centerX: 参照view的哪个属性,参照view的属性需要添加snp_make.centerX.equalTo(self.view.snp_centerX)
                
                make.centerX.equalTo(self.view)//当要约束的约束和参照的约束一样的时候,参照的约束可以省略
                make.bottom.equalTo(self.view.snp_bottom).offset(-160)
                
                // 约束消息label
                messageLabel.snp_makeConstraints(closure: { (make) -> Void in
                    make.centerX.equalTo(iconView)
                    make.top.equalTo(iconView.snp_bottom).offset(16)
                    
                })
            })
        }
        
    }
    
    // MARK: - 懒加载
    /// 背景
    private lazy var bkgView: UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    
    /// 头像
    private lazy var iconView: UIImageView = {
        
        let imageView = UIImageView(image: UIImage(named: "avatar_default_big"))
        //圆角
        imageView.layer.cornerRadius = 42.5
        imageView.layer.masksToBounds = true
        
        return imageView
    }()
    /// 消息label
    private lazy var messageLabel: UILabel = {
        let label = UILabel()
        //设置lebel
        label.text = "欢迎归来"
        label.textColor = UIColor.blackColor()
        label.font = UIFont.systemFontOfSize(15)
        label.sizeToFit()
        
        return label
    }()

}
